Created
June 29, 2018 12:49
-
-
Save skenderbeu/733eb475be5552d175b5dd4a0d23c338 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void createShipment( utcdatetime _shipmentDate, | |
SalesTable _salesTable, | |
str _noOfParcels = "1" | |
) | |
{ | |
RoyalMail.shippingAPIPortTypeClient serviceClient; | |
RoyalMail.createShipmentRequest shipmentRequest; | |
RoyalMail.createShipmentResponse shipmentResponse; | |
RoyalMail.contact contact; | |
RoyalMail.address address; | |
RoyalMail.requestedShipment requestedShipment; | |
RoyalMail.SecurityHeaderType securityHeaderType; | |
RoyalMail.integrationFooter integrationFooter; | |
ShipCarrierTrackingNum rmShipmentIdLocal; | |
System.Exception interopException; | |
SalesTable salesTable; | |
ZFSRMNotificationType notificationType; | |
container containerAddress; | |
str deliveryInstruction; | |
boolean signature; | |
RecId logRecId; | |
salesTable = _salesTable; | |
logRecId = this.logRequest(RM_RequestMethod::CreateShipment, salesTable.SalesId); | |
if(!this.parmShipmentCreationDate()) | |
{ | |
this.parmShipmentCreationDate(_shipmentDate); | |
} | |
if(!logRecId) | |
{ | |
logRecId = salesTable.RecId; | |
} | |
new InteropPermission(InteropKind::ClrInterop).assert(); | |
try | |
{ | |
serviceClient = this.getRMServiceClient(); | |
// Create Request | |
shipmentRequest = new RoyalMail.createShipmentRequest(); | |
shipmentRequest.set_integrationHeader(this.getIntegrationHeader(_salesTable.SalesId)); | |
contact = this.getContact(salesTable); | |
containerAddress = this.getAddressFields(SalesTable.deliveryAddress().Address); | |
address = this.getAddress(salesTable.deliveryAddress().City, containerAddress, salesTable.deliveryAddress().ZipCode, "GB"); | |
shipmentRequest.set_requestedShipment(this.getShipment( | |
contact,address, _shipmentDate, | |
notificationType, _noOfParcels, | |
salesTable.SalesId)); | |
securityHeaderType = this.GetSecurityHeaderType(logRecId); | |
// Handle Response | |
shipmentResponse = serviceClient.createShipment(securityHeaderType, shipmentRequest); | |
if(shipmentResponse) | |
{ | |
integrationFooter = shipmentResponse.get_integrationFooter(); | |
if(integrationFooter) | |
{ | |
this.processResponseWarnings(integrationFooter.get_warnings()); | |
if(!this.hasResponseErrors(integrationFooter.get_errors())) | |
{ | |
rmShipmentIdLocal = this.getShipmentID(shipmentResponse); | |
this.updateRequestLogStatus(logRecId); | |
} | |
} | |
else | |
{ | |
rmShipmentIdLocal = this.getShipmentID(shipmentResponse); | |
this.updateRequestLogStatus(logRecId); | |
} | |
} | |
else | |
{ | |
throw error("Error in response from Royal Mail create shipment service"); | |
} | |
serviceClient.Close(); | |
} | |
catch(Exception::CLRError) | |
{ | |
interopException = CLRInterop::getLastException(); | |
if(interopException) | |
{ | |
error(CLRInterop::getAnyTypeForObject(interopException.ToString())); | |
} | |
serviceClient.Abort(); | |
} | |
CodeAccessPermission::revertAssert(); | |
this.parmShipmentId(rmShipmentIdLocal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment