Andrew, knowing a bit about your ongoing project and having written the above procedure, I think you can simplify the code here. This function was written so it could be called in relation to a number of mounted packages, hence the package_id parameter. You can see further down in the code it retrieves the SMS Broker queue name from the package's parameter. Your system is using only one queue, which is "out". You can safely remove the package_id parameter, and either hardcode (blah!) the "out" queue name, or pull it from a more appropriate configuration location.
Hope that helps.