C#: Get The Status Of Multiple Letters by Range with GetLetterStatusV2_Range()

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 the values of the Const lines with your details:
    • Replace MyUsername and MyPassword with your PostalMethods user details.
    • Replace ID1 with the low LetterID of the range and ID2 with the high LetterID of the range for which you would like to get the status.
  4. 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 GetLetterStatusV2_Range
    {
 
        public static void Main()
        {
            const string MyUsername = "MyUsername";
            const string MyPassword = "MyPassword";
            const int MinID = 0;
            const int MaxID = 10;
 
            com.postalmethods.api.PostalWSSimple objPM = new com.postalmethods.api.PostalWSSimple();
            com.postalmethods.api.GetLetterStatusV2_RangeResult objResult = default(com.postalmethods.api.GetLetterStatusV2_RangeResult);
 
            //
            // Invoke the GetLetterStatus_Range method
            //
            objResult = objPM.GetLetterStatusV2_Range(MyUsername, MyPassword, MinID, MaxID);
 
            //
            // Check response status
            //
            if (objResult.ResultCode == -3000)
            {
                //
                // -3000 means that the data was successfully retrieved.
                //
                foreach (com.postalmethods.api.LetterStatusAndDesc status in objResult.LetterStatuses)
                {
                    Console.WriteLine("ID: {0}", status.ID);
                    Console.WriteLine("Last update time: {0}", status.LastUpdateTime);
                    Console.WriteLine("Status: {0}", status.Status);
                    Console.WriteLine("Status description: {0}", status.Description);
                    Console.WriteLine();
                }
            }
 
            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("Hit ENTER to terminate application");
            Console.ReadLine();
 
        }
    }
 
}