This document contains examples of typical use cases for the Delivery API. These examples demonstrate calls to the SOAP interface and are provided as is.
Full API documentation is available here.
The following examples demonstrate calls to the Delivery API in C#.
These examples 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 - you will need to point this program at your site's Delivery API endpoint. A detailed description of how to generate a web service client is beyond the scope of this document.
Note that these examples include minimal or no error handling. Any API callers are expected to handle errors appropriately.
// Instantiate the web service proxy.
DeliveryAPI service = new DeliveryAPI();
// Username and password to authenticate with.
string username = "Testing";
string password = "Sup94zex";
// Authenticate and retrieve authentication token.
ApiResponse authResponse = service.Authenticate(username, password);
string token = authResponse.Message;
DeliveryEnquiry enquiry = new DeliveryEnquiry {
Reference = Guid.NewGuid().ToString(),
WebsiteID = 1,
// Get both delivery and click and collect options.
DeliveryType = 3,
Postcode = "8042",
State = "South Island",
Country = "NZL",
Items = new[] {
new DeliveryEnquiryItem {
Barcode = "4011200296908",
Quantity = 1
}
}
};
// Call API and retrieve the response.
DeliveryOptionApiResponse response =
service.GetDeliveryOptions(token, new[] { enquiry });
// Check that the request succeeded.
if (response.Success) {
Console.WriteLine("Available delivery options:");
// Filter invalid delivery options.
var validOptions = response.Data.Where(o => o.Status == 0);
foreach (DeliveryOption opt in validOptions) {
// Display delivery option name and price.
Console.WriteLine("- {0} - ${1:N2}",
opt.DeliveryMethod,
opt.NetPrice
);
}
} else {
Console.WriteLine("ERROR: " + response.Message);
}
// Instantiate the web service proxy.
DeliveryAPI service = new DeliveryAPI();
// Username and password to authenticate with.
string username = "Testing";
string password = "Sup94zex";
// Authenticate and retrieve authentication token.
ApiResponse authResponse = service.Authenticate(username, password);
string token = authResponse.Message;
List<DeliveryEnquiry> enquiries = new List<DeliveryEnquiry>();
enquiries.Add(new DeliveryEnquiry {
Reference = Guid.NewGuid().ToString(),
WebsiteID = 1,
// Get both delivery and click and collect options.
DeliveryType = 3,
Postcode = "8042",
State = "South Island",
Country = "NZL",
Items = new[] {
new DeliveryEnquiryItem {
Barcode = "4011200296908",
Quantity = 1,
// Override unit price stored in the system.
UnitNet = 50
}
}
});
enquiries.Add(new DeliveryEnquiry {
Reference = Guid.NewGuid().ToString(),
WebsiteID = 1,
DeliveryType = 3, // Both delivery and click and collect options.
Postcode = "8052",
State = "South Island",
Country = "NZL",
Items = new[] {
new DeliveryEnquiryItem {
Barcode = "7501031311309",
Quantity = 2
}
}
});
// Call API and retrieve the response.
DeliveryOptionApiResponse response =
service.GetDeliveryOptions(token, enquiries.ToArray());
// Check that the request succeeded.
if (response.Success) {
foreach (DeliveryEnquiry enquiry in enquiries) {
Console.WriteLine("Reference: {0}", enquiry.Reference);
Console.WriteLine("Items:");
foreach (DeliveryEnquiryItem item in enquiry.Items) {
Console.WriteLine("- {0}x {1}", item.Quantity, item.Barcode);
}
// Identify valid delivery options for this Reference.
var options = response.Data
.Where(o => o.Status == 0 && o.Reference == enquiry.Reference);
Console.WriteLine("Delivery Options:");
foreach (DeliveryOption option in options) {
Console.WriteLine("- {0} - ${1:N2}",
option.DeliveryMethod,
option.NetPrice
);
}
Console.WriteLine(new string('-', 80));
}
} else {
Console.WriteLine("ERROR: " + response.Message);
}
// Instantiate the web service proxy.
DeliveryAPI service = new DeliveryAPI();
// Username and password to authenticate with.
string username = "Testing";
string password = "Sup94zex";
// Authenticate and retrieve authentication token.
ApiResponse authResponse = service.Authenticate(username, password);
string token = authResponse.Message;
DeliveryEnquiry enquiry = new DeliveryEnquiry {
Reference = Guid.NewGuid().ToString(),
WebsiteID = 1,
// Get only and click and collect options.
DeliveryType = 2,
Postcode = "1234",
State = "NSW",
Country = "AUS",
Items = new[] {
new DeliveryEnquiryItem {
Barcode = "4011200296908",
Quantity = 1
}
}
};
// Call API and retrieve the response.
DeliveryOptionApiResponse response =
service.GetDeliveryOptions(token, new[] { enquiry });
// Check that the request succeeded.
if (response.Success) {
// Filter invalid delivery options.
var validOptions = response.Data.Where(o => o.Status == 0);
// Since enquiry.DeliveryType limits the options to only click and
// collect delivery options, we just check if any results were returned.
if (validOptions.Any()) {
Console.WriteLine("Click and collect is available for this enquiry.");
} else {
Console.WriteLine("Click and collect is not available at this time.");
}
} else {
Console.WriteLine("ERROR: " + response.Message);
}