If the SIP provider does NOT pass the DID (in step 1 above), then it becomes trickier. One fall-back is to enroll with the SIP provider multiple times (i.e. have multiple accounts) and assign a required DID to each account. Then "in bound" calls to the 3cx can be routed based on which account they call came from. Its a bit sloppy and relies on you being able to align your DIDs with different accounts which may not be possible if they are already allocated and in use. But it does work well as a fallback approach where the DID is not sent by the SIP provider.

Probably not the simple answer you were hoping for. But hope that assists anyhow.