Cisco JTAPI provides all the API to do this. To get familiar with JTAPI, take a look at the JTAPI 1.2 specification on the web.
You want to go through JTAPI developer guide to understand how to create application user on CUCM, so that your custom application can connect to CUCM and control the call. The sample apps (makecall, jtrace) are good starting points. The source code for these are available in your Cisco JTAPI install folder. (You need to down load Cisco JTAPI from CUCM and install on your dev machine)
1. You need to create a CTIRoute point on CUCM admin and include it in the 'control list' of the application user you will be using in your app. The DN of the CTI Route point could be the number you want to intercept or a pattern that does the same.
2. Register the CTIRoute point in your application and register a call back on CTIPort. registerRouteCallback(RouteCallback) in RouteAddress is the API you should be using.
3. When one of the users dials the number application will see a 'ROUTE' event and then based on the calling number, selectRoute(String[] routeSelected, int callingSearchSpace, String[] modifyingCallingNumber) API in CiscoRouteSession can be used to change the calling party number.
You can use CiscoJTAPITest for POC on CTI Route Point intercepts the call and routes it to. CiscoJTAPITest should be available on devNet and there are couple of short videos on how to use it.