ASP: Cancel Delivery Of A Letter with CancelDelivery()

Instructions

  1. Create a new ASP page.
  2. Copy the entire code below and paste the code there.
  3. Replace MyUsername and MyPassword with your PostalMethods user details.
  4. Replace ID with the LetterID you would like to cancel.
  5. Start your application. If the response is -3000, PostalMethods is trying to cancel your letter. You should query its status. If the response is any other number, check the Web Service Status Codes section.
<% 
'
' This asp script demonstrates how to cancel a delivery of a Letter, using MS SOAP 3.0
' and the CancelDelivery method within PostalMethods. 
'
Option Explicit 
 
Const MyUsername = "MyUsername"
Const MyPassword = "MyPassword"
' Replace with the LetterID of the Letter, as returned by the sending method, such as SendLetter()
Const LetterID="ID" 
 
Dim objSoap, lngResult
'
'Create the SoapClient object    'MS SOAP v3.0
'
Set objSoap = Server.CreateObject("MSSOAP.SOAPClient30")
'
'Set to True when an Active Server Pages (ASP) application or an ISAPI DLL uses the SoapClient object.
'
objSoap.ClientProperty("ServerHTTPRequest") = True 
'
'Initializes the SoapClient object. ASP initializes the WSDL on each call. 
'For better performance, you may download the WSDL locally as an XML and refer to the local file.
'
objSoap.mssoapinit("http://api.postalmethods.com/PostalWS.asmx?WSDL")
'
'Set to True when a proxy server is to be detected automatically
'
objSoap.ConnectorProperty("EnableAutoProxy") = True
'
' Invoke the SendLetter method
'
lngResult = objSoap.CancelDelivery( _
				MyUsername, _
				MyPassword, _
				LetterID)
 
If CLng(lngResult) = -3000 Then 
	'
	' -3000 means the request was successfully marked for cancellation.
	'
	Response.Write "Letter was requested to be canceled"
Else 
	'
	' A value less than -3000 means an error occurred.
	' See the PostalMethods Status Codes: http://www.postalmethods.com/statuscodes.
	'
    Response.Write "Error is:" & lngResult
End If
 
%>