If there is a last gateway set for the channel and the context group (if exists), then it is chosen as via.
Else, if there is a last gateway set globally for that user channel,it is used.
Otherwise, if there is no last gateway defined, and there is a context group, the message is routed via all the group's active local gateways, if there are any. All local gateways, both owned and shared to, are used.
If no local gateways are defined for the channel's protocol within the group, then shared gateways are used:
If the message is sent to a SMS, then country and provider information is used. If both are set, the corresponding gateway is used. If only country information is available, then the message is broadcasted through all numbers defined for that country.
Otherwise, if the message is not sent to a SMS, or the country is not specified, then all shared gateways specified for that protocol are used.