C#: Get The Status Of A Letter with GetStatus()

Instructions

  1. Create a new Console Application project and add a web reference
  2. Copy the entire code below, delete anything written in your application and paste the code there
  3. Replace "MyUsername" and "MyPassword" with your PostalMethods user details
  4. Replace "IDs" with a single ID of one of your sent mail items, multiple IDs (ID1,ID2,ID3) or a range of IDs (ID1-ID2)
  5. Start your application. If the response is -3000, you will see the status report. If the response is any other number, check the Web Service Status Codes section.
using System;
 
namespace ConsoleApplication1
{
    class GetStatus
    {
        public static void Main()
        {
            const string MyUsername = "MyUsername";
            const string MyPassword = "MyPassword";
            const string IDs = "0";       // To query a single mail item
            //const string IDs = "0,0,0"; // To query multiple mail items
            //const string IDs = "0-0";   // To query a range of mail items
 
 
            com.postalmethods.api.PostalWS objPM = new com.postalmethods.api.PostalWS();
            com.postalmethods.api.GetStatusResult objResult = default(com.postalmethods.api.GetStatusResult);
 
            //
            // Invoke the GetStatus method
            //
 
            objResult = objPM.GetStatus(MyUsername, MyPassword, IDs);
 
            //
            // Check response status
            //
            if (objResult.ResultCode == -3000)
            {
                //
                // -3000 means that the statuses were successfully retrieved.
                // Write them down.
                //
                Console.WriteLine("Successfully retrieved results");
                foreach (com.postalmethods.api.LetterStatusAndDesc Status in objResult.Statuses)
                {
                    WriteStatus(Status);
                }
            }
            else
            {
                //
                // A value less than -3000 means an error occurred.
                // See the PostalMethods Status Codes: http://www.postalmethods.com/statuscodes.
                //
                Console.WriteLine("Error is:" + objResult.ResultCode);
            }
 
            // In debug mode, the following lines prevent your console application from closing automatically upon termination
            Console.WriteLine("**********************************");
            Console.WriteLine("Hit ENTER to terminate application");
            Console.ReadLine();
 
        }
 
        private static void WriteStatus(com.postalmethods.api.LetterStatusAndDesc Status)
        {
            Console.WriteLine("**********************************");
            Console.WriteLine("ID: " + Status.ID);
            Console.WriteLine("Status: " + Status.Status);
            Console.WriteLine("Status Description: " + Status.Description);
            Console.WriteLine("Status Last Update Time: " + Status.LastUpdateTime);
        }
 
    }
}