It looks like you are working with a custom shipping implementation. You should create a testing script with your code to see if you are getting a good response from your provider. I'm not familiar with the provider you using so I'm not sure how you ensure that you are sending the information successfully and getting a valid response. You should refer to your shipping providers development documentation to get this info.
Once you have tested you script and can confirm that you are getting back a valid value you can then store that amount in a session variable and setup a new shipping charge rule to work with this new session variable.