You need an USSD server/gateway in your mobile network operators environment, connected to the operators SS7 network. USSD messages can be sent either from mobile phone to USSD server or from USSD server to mobile phone. It is not possible to send an USSD message directly from one phone to another, you would need to relay the message via the USSD server.
USSD messages are not standardized, they are specific to the mobile network and the USSD-capable applications. However, there are some de-facto standard USSD messages understood by many HLRs for querying and configuring things like call forwarding.
USSD is transported via SS7 using the MAP protocol. The business logic implemented on top of MAP is bound to the actual protocol stack implementation. On the server side that could be hardware (interface cards) plus operating system drivers or software-only, e.g. a SIGTRAN-Stack, depending on the physical layer to be supported (E1, SDH over fiber, ATM or Ethernet). A sample application depends on the protocol stack it runs on. Look for sample applications from the vendor of your interface hardware or protocol stack. On the client side the USSD support is device-dependent, e.g. via J2ME JSR 120 "Wireless Messaging API".
USSD is not guaranteed to be delivered, especially not in roaming scenarios. That solely depends on your mobile network operator. If you do not have an agreement with the operator, he might firewall away your USSD messages, especially if he detects high volumes circumventing his pay-messaging services.