Before writing APEX code, please install the ShipAutomate package here.

Bulk Domestic Shipments

// Service Types
// Domestic: UPS Next Day Air Early A.M.
// Domestic: UPS Next Day Air
// Domestic: UPS Next Day Air Saver
// Domestic: UPS 2nd Day Air A.M.
// Domestic: UPS 2nd Day Air
// Domestic: UPS 3 Day Select
// Domestic: UPS Ground
// Packaging Types
// UPS Letter
// UPS Small Express Box
// UPS Medium Express Box
// UPS Large Express Box
// UPS PAK
// UPS Tube
// Your Packaging

// collect record ids
Id shippingPrefId = 'a02U000000RN8Lk';
Id contactId = '003U0000002nlwt';

zkups__UPSShipmatePreference__c shipmatePref = [
SELECT Id, Name,
zkups__UserId__c, zkups__UserIdVisible__c, zkups__UPSAccountNumber__c,
zkups__ThermalPrinterName__c, zkups__Street__c, zkups__State__c, zkups__SenderPhoneDefault__c,
zkups__SenderNameDefault__c, zkups__SenderEMailDefault__c, zkups__SendEMailNotificationToShipper__c,
zkups__SendEMailNotificationToRecipient__c, zkups__PrimaryContactTitle__c, zkups__PrimaryContactPhone__c,
zkups__PrimaryContactName__c, zkups__PrimaryContactEmail__c, zkups__PostalCode__c, zkups__Password__c,
zkups__LabelImageTypeDefault__c, zkups__EMailNotifyOnExceptionDefault__c, zkups__EMailNotifyOnDeliveryDefault__c,
zkups__EMailMessageDefault__c, zkups__DetailedViewShipmatePreferenceList__c, zkups__DetailedViewReUsePackageList__c,
zkups__Country__c, zkups__CompanyURL__c, zkups__CompanyName__c, zkups__City__c, zkups__AccessLicenseNumber__c,
zkups__ShippingStreet__c, zkups__ShippingCity__c, zkups__ShippingState__c, zkups__ShippingPostalCode__c,
zkups__ShippingCountry__c, zkups__ShippingIsResidential__c
FROM zkups__UPSShipmatePreference__c
WHERE Id = :shippingPrefId];



// 1. zkups__BulkShipment__c object
zkups__BulkShipment__c bulkShipment = new zkups__BulkShipment__c (
zkups__ShipmatePreference__c = shipmatePref.Id
);
insert bulkShipment;

// Get Contact
Contact con = [
SELECT MailingCity, Account.Name, MailingCountry,
 Email, FirstName, LastName,
Phone, MailingState, MailingStreet,
  MailingPostalCode
FROM Contact
WHERE Id = :contactId];

// 2. zkups__QueuedShipment__c object
zkups__QueuedShipment__c queuedShipment = new zkups__QueuedShipment__c (
zkups__BulkShipment__c = bulkShipment.Id,
zkups__LabelImageType__c = 'GIF',
zkups__ServiceType__c = 'Domestic: UPS Ground',
zkups__PackagingType__c = 'Your Packaging',

// sender info
zkups__SenderName__c = shipmatePref.zkups__SenderNameDefault__c,
zkups__SenderCity__c = shipmatePref.zkups__ShippingCity__c,
zkups__SenderCompany__c = shipmatePref.zkups__CompanyName__c,
zkups__SenderEmail__c = shipmatePref.zkups__SenderEMailDefault__c,
zkups__SenderPhone__c = shipmatePref.zkups__SenderPhoneDefault__c,
zkups__SenderState__c = shipmatePref.zkups__ShippingState__c,
zkups__SenderStreet__c = shipmatePref.zkups__ShippingStreet__c,
zkups__SenderPostalCode__c = shipmatePref.zkups__ShippingPostalCode__c,
zkups__SenderCountry__c = 'US',

// UPS specific fields
zkups__PaymentType__c = 'Sender',
zkups__WeightDimensionUnits__c = 'LB / IN',
// zkups__DimensionUnits__c = 'KG / CM',

// recipient info
zkups__RecipientName__c = con.FirstName + ' ' + con.LastName,
zkups__RecipientCity__c = con.MailingCity,
zkups__RecipientCompany__c = con.Account.Name,
zkups__RecipientCountry__c = con.MailingCountry,
zkups__RecipientEmail__c = con.Email,
// TODO: need format zkups__RecipientPhone__c = con.Phone,
zkups__RecipientPhone__c = '2125551234',
zkups__RecipientState__c = con.MailingState,
zkups__RecipientStreet__c = con.MailingStreet,
zkups__RecipientPostalCode__c = con.MailingPostalCode,
zkups__Contact__c = con.Id

);
insert queuedShipment;
// 3. zkups__QueuedPackage__c object
zkups__QueuedPackage__c queuedPackage = new zkups__QueuedPackage__c (
zkups__DeclaredValue__c = 1,
zkups__Weight__c = 1,
zkups__Height__c = 1,
zkups__Length__c = 1,
zkups__Width__c = 1,
zkups__QueuedPackageSpecialServices__c = null,
zkups__QueuedShipment__c = queuedShipment.Id        
);
insert queuedPackage;


// validation
// String batchId = zkups.BulkShipmentInterface.validateBulkShipment(bulkShipment.Id, false);
String batchId = zkups.BulkShipmentInterface.processBulkShipment(bulkShipment.Id);
System.debug('BATCH ID :' + batchId);

Bulk International Shipments

// Service Types
// Domestic: UPS Next Day Air Early A.M.
// Domestic: UPS Next Day Air
// Domestic: UPS Next Day Air Saver
// Domestic: UPS 2nd Day Air A.M.
// Domestic: UPS 2nd Day Air
// Domestic: UPS 3 Day Select
// Domestic: UPS Ground
// International: UPS Worldwide Express
// International: UPS Worldwide Expedited
// International: UPS Express Saver
// International: UPS Worldwide Express Plus
// Packaging Types
// UPS Letter
// UPS Small Express Box
// UPS Medium Express Box
// UPS Large Express Box
// UPS PAK
// UPS Tube
// Your Packaging

// collect record ids
Id shippingPrefId = 'a02U000000RN8Lk'; // Sandbox pref
Id contactId = '003U0000002nlx4'; // Ms. Ashley James - UK
Id commodityDataId = 'a07U000000laHhA'; // a07U000000FhQHB
Id eeiId = 'a0AU000001HM19t'; // real: a0AU0000009igpr
Id commercialInvoiceId = 'a09U0000006Yvly';
Id natfaCoId = 'a0BU0000004tSvA';

zkups__UPSShipmatePreference__c shipmatePref = [
SELECT Id, Name,
zkups__UserId__c, zkups__UserIdVisible__c, zkups__UPSAccountNumber__c,
zkups__ThermalPrinterName__c, zkups__Street__c, zkups__State__c, zkups__SenderPhoneDefault__c,
zkups__SenderNameDefault__c, zkups__SenderEMailDefault__c, zkups__SendEMailNotificationToShipper__c,
zkups__SendEMailNotificationToRecipient__c, zkups__PrimaryContactTitle__c, zkups__PrimaryContactPhone__c,
zkups__PrimaryContactName__c, zkups__PrimaryContactEmail__c, zkups__PostalCode__c, zkups__Password__c,
zkups__LabelImageTypeDefault__c, zkups__EMailNotifyOnExceptionDefault__c, zkups__EMailNotifyOnDeliveryDefault__c,
zkups__EMailMessageDefault__c, zkups__DetailedViewShipmatePreferenceList__c, zkups__DetailedViewReUsePackageList__c,
zkups__Country__c, zkups__CompanyURL__c, zkups__CompanyName__c, zkups__City__c, zkups__AccessLicenseNumber__c,
zkups__ShippingStreet__c, zkups__ShippingCity__c, zkups__ShippingState__c, zkups__ShippingPostalCode__c,
zkups__ShippingCountry__c, zkups__ShippingIsResidential__c
FROM zkups__UPSShipmatePreference__c
WHERE Id = :shippingPrefId];



// 1. zkups__BulkShipment__c object
zkups__BulkShipment__c bulkShipment = new zkups__BulkShipment__c (
zkups__ShipmatePreference__c = shipmatePref.Id
);
insert bulkShipment;

// Get Contact
Contact con = [
SELECT MailingCity, Account.Name, MailingCountry,
 Email, FirstName, LastName,
Phone, MailingState, MailingStreet,
  MailingPostalCode
FROM Contact
WHERE Id = :contactId];

// 2. zkups__QueuedShipment__c object
zkups__QueuedShipment__c queuedShipment = new zkups__QueuedShipment__c (
zkups__BulkShipment__c = bulkShipment.Id,
zkups__LabelImageType__c = 'GIF',
zkups__ServiceType__c = 'International: UPS Express Saver',
zkups__PackagingType__c = 'Your Packaging',

// sender info
zkups__SenderName__c = 'Sender Name', // shipmatePref.zkups__SenderNameDefault__c if field filled
zkups__SenderCity__c = shipmatePref.zkups__ShippingCity__c,
zkups__SenderCompany__c = shipmatePref.zkups__CompanyName__c,
zkups__SenderEmail__c = shipmatePref.zkups__SenderEMailDefault__c,
zkups__SenderPhone__c = shipmatePref.zkups__SenderPhoneDefault__c,
zkups__SenderState__c = shipmatePref.zkups__ShippingState__c,
zkups__SenderStreet__c = shipmatePref.zkups__ShippingStreet__c,
zkups__SenderPostalCode__c = shipmatePref.zkups__ShippingPostalCode__c,
zkups__SenderCountry__c = 'US',

// UPS specific fields
zkups__PaymentType__c = 'Sender',
zkups__DutiesPaymentType__c = 'Sender',
zkups__WeightDimensionUnits__c = 'LB / IN',
// zkups__DimensionUnits__c = 'KG / CM',

// recipient info
zkups__RecipientName__c = con.FirstName + ' ' + con.LastName,
zkups__RecipientCity__c = con.MailingCity,
zkups__RecipientCompany__c = con.Account.Name,
// zkups__RecipientCountry__c = con.MailingCountry,
zkups__RecipientCountry__c = 'UK',
zkups__RecipientEmail__c = con.Email,
// TODO: need format zkups__RecipientPhone__c = con.Phone,
zkups__RecipientPhone__c = '441914956203',
zkups__RecipientState__c = con.MailingState,
zkups__RecipientStreet__c = con.MailingStreet,
zkups__RecipientPostalCode__c = con.MailingPostalCode,
zkups__Contact__c = con.Id,
// International specific fields
zkups__ShipmentDescription__c = 'abcd',
zkups__Currency__c = 'GBP'

);
insert queuedShipment;

// 3. zkups__QueuedPackage__c object
zkups__QueuedPackage__c queuedPackage = new zkups__QueuedPackage__c (
zkups__DeclaredValue__c = 1,
zkups__Weight__c = 1,
zkups__Height__c = 1,
zkups__Length__c = 1,
zkups__Width__c = 1,
zkups__QueuedPackageSpecialServices__c = null,
zkups__QueuedShipment__c = queuedShipment.Id        
);
insert queuedPackage;

// 4. zkups__QueuedInternationalCommodity__c object
// create international commodity items
List<zkups__QueuedInternationalCommodity__c> queuedIntlCommodityList = new List<zkups__QueuedInternationalCommodity__c>();
// case 1: set data using commodity data
zkups__QueuedInternationalCommodity__c intlCommodity1 = new zkups__QueuedInternationalCommodity__c();
intlCommodity1.zkups__Queued_Shipment__c = queuedShipment.Id;
intlCommodity1.zkups__International_Commodity__c = commodityDataId;
intlCommodity1.zkups__Quantity__c = 1;

queuedIntlCommodityList.add(intlCommodity1);

// case 2: fill object manually  (without commodity data object)
zkups__QueuedInternationalCommodity__c intlCommodity2 = new zkups__QueuedInternationalCommodity__c();
intlCommodity2.zkups__CountryOfManufacture__c = 'US';
intlCommodity2.zkups__Description__c = 'Socks';
intlCommodity2.zkups__ExportType__c = 'Domestic';
intlCommodity2.zkups__JointProduction__c = false;
intlCommodity2.zkups__NumberOfPieces__c = 1;
intlCommodity2.zkups__UnitOfMeasurementOther__c = '123';
intlCommodity2.zkups__PartNumber__c = '123';
intlCommodity2.zkups__PreferenceCriteria__c = null;
intlCommodity2.zkups__UnitValue__c = 3.0;
intlCommodity2.zkups__ProducerInfo__c = 'The shipper is the producer of the good';
intlCommodity2.zkups__ScheduleBNumber__c = '6115950000';
intlCommodity2.zkups__ScheduleBUnitOfMeasurementCode__c = 'Dozen';
intlCommodity2.zkups__CommodityCode__c = null;
intlCommodity2.zkups__UnitOfMeasurement__c = 'Bolt';
intlCommodity2.zkups__VehicleId__c = '123';
intlCommodity2.zkups__Weight__c = 2.0;
intlCommodity2.zkups__WeightUnits__c = 'LBS';

intlCommodity2.zkups__Queued_Shipment__c = queuedShipment.Id;
intlCommodity2.zkups__Quantity__c = 1;
queuedIntlCommodityList.add(intlCommodity2);


insert queuedIntlCommodityList;

// 5. zkups__QueuedShipmentDocuments__c object
// create intl documents
zkups__QueuedShipmentDocuments__c queuedShipmentDocuments = new zkups__QueuedShipmentDocuments__c();
queuedShipmentDocuments.zkups__NAFTA_CO__c = null;
queuedShipmentDocuments.zkups__EEI_Form__c = eeiId;
queuedShipmentDocuments.zkups__Export_Date__c = Date.today();
queuedShipmentDocuments.zkups__Override_Paperless_Invoicing__c = false;
queuedShipmentDocuments.zkups__CertificateOfOrigin__c = true;
queuedShipmentDocuments.zkups__Invoice_Line_Total__c = null; // IF Commercial Invoice from is submitted

queuedShipmentDocuments.zkups__Queued_Shipment__c = queuedShipment.Id;

insert queuedShipmentDocuments;

// validation
String batchId = zkups.BulkShipmentInterface.processBulkShipment(bulkShipment.Id);
System.debug('BATCH ID :' + batchId);

Calculate Rates

Method Signature

global static List<ShipmentRate> calculateRates(QueuedShipment__c queuedShipment, List<QueuedPackage__c> queuedPackages, QueuedShipmentSpecialServices__c specialServices, 
List<QueuedPackageSpecialServices__c> packagesSecialServices,  UPSShipmatePreference__c shipmatePreference) {

}

Rate Response Format

global class ShipmentRate {

    global String shipmentProvider { get; set;}
    global String mailService { get; set; }
    global String currencyIsoCode { get; set; }
    global Decimal cost { get; set; }

    global ShipmentRate() {
        shipmentProvider = 'UPS';
    }
}

Did this answer your question?