Dispatch API Examples - C#

Overview

This document reflects over the aforementioned use cases of the Dispatch API. All examples defined within demonstrate calls to the SOAP interface and are provided as is.

Requirements

The following examples demonstrate calls to the Dispatch API in C#. .NET examples demonstrated here assume the use of a generated XML web service client. To generate such a client, a tool such as WSDL.exe can be used. A detailed description on this tool can be found on MSDN, but all you will need to do is point it at your site's WSDL description.

.NET examples utilise the Microsoft .NET Framework component LINQ

Retrieve a single dispatch point's details.

// Instantiate the web service proxy.
DispatchAPI service = new DispatchAPI();

// User to authenticate with.
String username = "Testing";
// Corresponding password to authenticate with.
String password = "Sup94zex";

// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);

// Dispatch Point name to search the Dispatch Database for.
String dispatchPointName = "Dispatch Point 1";

// Retrieve the dispatch point
DispatchPointApiResponse retrieveResponse = 
	service.RetrieveDispatchPoint(
		authenticationResponse.Message, dispatchPointName
	);

// Examine the DispatchPointApiResponse for our dispatch point.
if (retrieveResponse.Data.Count() == 0) {
	Console.WriteLine(
		"Failed to retrieve dispatch point: {0}", dispatchPointName
	);
} else {
	// Extract the dispatch point from the response.
	DispatchPoint dispatchPoint = retrieveResponse.Data.First();
}
				

Lists all dispatch points available to authenticated user.

// Instantiate the web service proxy.
DispatchAPI service = new DispatchAPI();

// User to authenticate with.
String username = "Testing";
// Corresponding password to authenticate with.
String password = "Sup94zex";

// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);

// List all the dispatch points available for the authenticated user.
DispatchPointApiResponse listResponse = 
	service.ListDispatchPoints(authenticationResponse.Message);
listResponse.Data.AsParallel().ForAll(x => Console.WriteLine(x.Code));
				

Lists all order IDs in a dispatch point.

// Instantiate the web service proxy.
DispatchAPI service = new DispatchAPI();

// User to authenticate with.
String username = "Testing";
// Corresponding password to authenticate with.
String password = "Sup94zex";

// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);

// Dispatch Point name to search the Dispatch Database for.
String dispatchPointName = "Dispatch Point 1";

// Obtain a list of order IDs for the provided dispatch point.
IntegerArrayApiResponse listResponse = service.ListOrders(
	authenticationResponse.Message, dispatchPointName
);
listResponse.Data.AsParallel().ForAll(x => Console.WriteLine(x));
				

Execute a dispatch action with return data e.g. allocate item using barcode.

// Instantiate the web service proxy.
DispatchAPI service = new DispatchAPI();

// User to authenticate with.
String username = "Testing";
// Corresponding password to authenticate with.
String password = "Sup94zex";

// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);

// Barcode and Dispatch Point name to use.
String barcode = "APN_1_2";
String dispatchPointName = "Dispatch Point 1";

// Execute the action and obtain the response
IntegerArrayApiResponse actionResponse = service.AllocateBarcode(
	authenticationResponse.Message, dispatchPointName, barcode
);

// Examine the IntegerArrayApiResponse for our order item id.
if (actionResponse.Data.Count() == 0) {
	Console.WriteLine("Failed to allocate item: {0}", barcode);
} else {
	// Extract the order item id from the response.
	int orderItemID = actionResponse.Data.First();
}
				

Execute a dispatch action with no return data e.g. assign order to dispatch point.

// Instantiate the web service proxy.
DispatchAPI service = new DispatchAPI();

// User to authenticate with.
String username = "Testing";
// Corresponding password to authenticate with.
String password = "Sup94zex";

// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);

// Order ID and Dispatch Point name to use.
int orderID = 12345;
String dispatchPointName = "Dispatch Point 1";

// Execute the action and obtain the response
ApiResponse actionResponse = service.AssignOrder(
	authenticationResponse.Message, dispatchPointName, orderID
);

// Check  the ApiResponse for success/failure.
if (actionResponse.Success) {
	Console.WriteLine("Successfully assigned order: {0}", orderID);
} else {
	Console.WriteLine("Failed to assign order: {0}", orderID);
}