Implementing the IGroupAdapter Interface |
The Group adapter can be used to manage grouping and document printing for multiple related shipments
Click here for a list of all members of the IGroupAdapter interface
Note |
---|
All Adapters must have this configuration interface implemented in order for the adapter to function. See IAdapterConfigurationProvider for a sample implementation of IAdapterConfigurationProvider. |
Below is a partial sample of an implementation of IGroupAdapter with examples of CreateGroup, OpenGroup, GetGroups, and several other methods.
public CloseGroupResponse CloseGroup(string carrier, string groupingSymbol, string groupId) { CloseGroupResponse result = new CloseGroupResponse(); //serialize request XElement xdoc = new XElement("modifyGroupRequest", new XElement("provider", Provider.ShipCo)); xdoc.Add(new XElement("carrier", carrier)); xdoc.Add(new XElement("groupingSymbol", groupingSymbol)); xdoc.Add(new XElement("groupId", groupId)); xdoc.Add(renameRootNode(serializeObject(new PackageRequest()),"fieldData")); string modifyGroupRequest = xdoc.ToString(); CmsConnectorShip client = new CmsConnectorShip(_shipUri); try { string response = client.ModifyGroup(modifyGroupRequest); result = (CloseGroupResponse)GetResponse(response, typeof(CloseGroupResponse)); //update database _groupingHelper.UpdateGroupStatus(carrier,groupId,2); } catch (Exception ex) { result.error_message = ex.Message; result.error_code = 1001; throw; } finally { client.Dispose();} return result; } public Group CreateGroup(string carrier, string groupingSymbol, PackageRequest pkgReq) { var group = new Group(); string consolidationCarrier = "SCX"; switch (groupingSymbol) { case "IPD": consolidationCarrier = "SCE"; break; case "IGD": case "IGDD": consolidationCarrier = "SCG"; break; case "TD": consolidationCarrier = "SCT"; break; } pkgReq.consolidation_carrier = consolidationCarrier; //serialize request var xdoc = new XElement("createGroupRequest", new XElement("provider", Provider.ShipCo)); xdoc.Add(new XElement("carrier", carrier)); xdoc.Add(new XElement("groupingSymbol", groupingSymbol)); xdoc.Add(renameRootNode(serializeObject(pkgReq), "field_data")); string createGroupRequest = xdoc.ToString(); CmsConnectorShip client = new CmsConnectorShip(_shipUri); try { //open group in ShipCo string response = client.CreateGroup(createGroupRequest); Group groupResponse = (Group)GetResponse(response, typeof(Group)); if (groupResponse.error_code == 0) { group.date_opened = new SoxDate(); pkgReq.consolidation_type = groupingSymbol; group.field_data = pkgReq; group.friendly_name = pkgReq.consolidation_code; //status, 1 = open, 2 = closed, 4 = closedandlocked group.status = 1; group.symbol = groupingSymbol; //open group in database _groupingHelper.CreateGroup(carrier, ref group); } else { group.error_code = groupResponse.error_code; group.error_message = groupResponse.error_message; } } catch (Exception ex) { group.error_code = 1001; group.error_message = ex.Message; throw; } finally { client.Dispose();} return group; } public bool ModifyGroup(string carrier, string groupingSymbol, string groupId, PackageRequest pkgReq) { bool result = true; //serialize request XElement xdoc = new XElement("modifyGroupRequest", new XElement("provider", Provider.ShipCo)); xdoc.Add(new XElement("carrier", carrier)); xdoc.Add(new XElement("groupingSymbol", groupingSymbol)); xdoc.Add(new XElement("groupId", groupId)); xdoc.Add(renameRootNode(serializeObject(pkgReq), "fieldData")); string modifyGroupRequest = xdoc.ToString(); CmsConnectorShip client = new CmsConnectorShip(_shipUri); try { //modify ShipCo string response = client.ModifyGroup(modifyGroupRequest); Group groupResponse = (Group)GetResponse(response, typeof(Group)); //update database _groupingHelper.UpdateGroup(pkgReq,groupId); } catch (Exception) { result = false; throw; } finally { client.Dispose();} return result; } public Group GetGroup(string carrier, string groupingSymbol, string groupId) { int groupID = _groupingHelper.GetGroupId(carrier,groupId); Group group = null; try { group = _groupingHelper.GetGroup(carrier, groupID); } catch (Exception) { group = null; } return group; } public List<SoxGroupingType> GetGroupingTypes() { List<SoxGroupingType> result = new List<SoxGroupingType>(); result.Add(new SoxGroupingType() { Carrier = "PSI_CMS.ShipCo", Symbol = "IPD", FriendlyName = "ShipCo International Priority Direct Distribution", GroupIDField = "CONSOLIDATION_ID" }); result.Add(new SoxGroupingType() { Carrier = "PSI_CMS.ShipCo", Symbol = "TD", FriendlyName = "ShipCo Transborder Distribution", GroupIDField = "CONSOLIDATION_ID" }); result.Add(new SoxGroupingType() { Carrier = "PSI_CMS.ShipCo", Symbol = "IGD", FriendlyName = "ShipCo International Ground Distribution", GroupIDField = "CONSOLIDATION_ID" }); result.Add(new SoxGroupingType() { Carrier = "PSI_CMS.ShipCo", Symbol = "IGDD", FriendlyName = "ShipCo International Ground Direct Distribution", GroupIDField = "CONSOLIDATION_ID" }); return result; } public List<Sox.Grouping> GetGroupings(string carrier) { List<Sox.Grouping> result = new List<Sox.Grouping>(); result.Add(new Sox.Grouping() { symbol = "IPD", name = "ShipCo International Priority Direct Distribution", group_id_field = "CONSOLIDATION_ID" }); result.Add(new Sox.Grouping() { symbol = "TD", name = "ShipCo Transborder Distribution", group_id_field = "CONSOLIDATION_ID" }); result.Add(new Sox.Grouping() { symbol = "IGD", name = "ShipCo International Ground Distribution", group_id_field = "CONSOLIDATION_ID" }); result.Add(new Sox.Grouping() { symbol = "IGDD", name = "ShipCo International Ground Direct Distribution", group_id_field = "CONSOLIDATION_ID" }); return result; } public List<Group> GetGroups(string carrier, string groupingSymbol, int statusFlag) { //This is a list of groups, open, closed, closedandlocked //pull from database List<Group> groups = _groupingHelper.GetGroups(carrier, groupingSymbol, statusFlag); return groups; } public bool OpenGroup(string carrier, string groupingSymbol, string groupId) { bool result = true; //serialize request XElement xdoc = new XElement("createGroupRequest", new XElement("provider", Provider.ShipCo)); xdoc.Add(new XElement("carrier", carrier)); xdoc.Add(new XElement("groupingSymbol", groupingSymbol)); xdoc.Add(new XElement("groupId", groupId)); xdoc.Add(renameRootNode(serializeObject(new PackageRequest()), "fieldData")); string modifyGroupRequest = xdoc.ToString(); CmsConnectorShip client = new CmsConnectorShip(_shipUri); try { string response = client.ModifyGroup(modifyGroupRequest); Group groupResponse = (Group)GetResponse(response, typeof(Group)); _groupingHelper.UpdateGroupStatus(carrier,groupId,1); } catch (Exception) { result = false; throw; } finally { client.Dispose(); } return result; }