Data Management Capabilities > Managing Part Structures > Windchill Options and Variants Capabilities > Creating and Managing Variants > Variant Specification Information Page > Loading Variant Specifications > Loading Variant Specifications Using an API > Loading Variant Specifications Using API #2 > Sample Code for API #2
  
Sample Code for API #2
Below is a sample code for using API #2 for loading variant specifications.
//Create 1 VariantSpecLoadOutputBean per variant specification you want to create
VariantSpecLoadOutputBean myRow1Bean = new VariantSpecLoadOutputBean();

//Set the correct part to use. Make sure the part has an assigned option set
WTPart part = VariantSpecLoaderHelper.serivce.getWTPart("BICYCLE3", “A”, “1”);

//Set the option set with the assigned option set for the part.
OptionSet optionSet = VariantSpecLoaderHelper.serivce.getAssignedOptionSet(part);

//If you are creating a variant specification based on an option set and not a
//part, do not set the part on the bean. Instead set the option set to the one
//you want to base the variant specification on

//OptionSet optionSet = VariantSpecLoaderHelper.serivce.getOptionSet("Bicycle3 Option
Set Template", myContainerReference);

//Get the folder to save the variant specification in
Folder folder = FolderHelper.service.getFolder("/Default/",
myPartContainerReference);

// You can use an existing navigation criteria from the database (for testing)
// or create one brand new like below

NavigationCriteria nc = NavigationCriteria.newNavigationCriteria();
nc.setApplyToTopLevelObject(true);
nc.setUseDefaultForUnresolved(true);
nc.setName(DocHelper.service.autogenerateNavigationCriteriaName());
nc.setOwner((WTUser) SessionHelper.getPrincipal());
nc.setApplicableType(WTPart.class.getName());


// Add Part Configuration Specifications to this criteria. You can also use
//default which is latest. Existing criteria will already have a config specs
//assigned

WTPartConfigSpec myPartConfigSpec = (WTPartConfigSpec)
ConfigHelper.service.getDefaultConfigSpecFor(WTPart.class, myPartContainerReference);

// NOTE : The configuration specifications must always be persisted before
adding to a navigation criteria
List<WTPartConfigSpec> partSpecs = new ArrayList<WTPartConfigSpec>();
partSpnc.setPartConfigSpecs(partSpecs);
nc.setPartConfigSpecs(partSpecs);

//If using new navigation criteria, create a new ATONavigationFilter (if you
//have choices you want to filter by)

ATONavigationFilter filter = ATONavigationFilter.newATONavigationFilter();
filter.setFilterMode(navCriteriaBean.getFilterMode());
filter.setOptionSet(optionSet);
filter.setRuleCheckingDisabled(navCriteriaBean.isRuleCheckingDisabled());

// Set the Options filter configuration specification. The one below is a
//latest configuration specification

List <ATORuleConfigSpec> atoRuleConfigs = new ArrayList<ATORuleConfigSpec>();
ATORuleConfigSpec atoRuleConfigSpec =ATORuleConfigSpec.newATORuleConfigSpec();
atoRuleConfigSpec.setEffActive(false);
atoRuleConfigSpec.setLatestActive(false);
atoRuleConfigSpec.setLifeCycleActive(true);

atoRuleConfigSpec = (ATORuleConfigSpec)PersistenceHelper.manager.store(atoRuleConfigSpec);
atoRuleconfigs.add(atoRuleConfigSpec);
filter.setConfigSpecs(atoRuleConfigs);

// Now add the filter to the navigation criteria ArrayList<NavigationFilter2> filterList = new ArrayList<NavigationFilter2>(1);
filterList.add(filter);
nc.setFilters(filterList);

// Setup the choices to select for the Options filter
Map<String, Set<String>> optionToChoiceMap = new HashMap<String,

// Steering Type : D30010 Set<String> choiceSet = new HashSet<String>();

Option testOptionA = MyHelper.getOption ("Steering Type",
part.getContainerReference());
Choice testChoice = MyHelper.getChoice("D30010", "Steering Type",
part.getContainerReference());

choiceSet.add(testChoice.getPersistInfo().getObjectIdentifier().toString());
optionToChoiceMap.put(testOption.getPersistInfo().getObjectIdentifier().toString(), choiceSet);

// Suspension : D30021
testOption = MyHelper.getOption ("Suspension", part.getContainerReference());
testChoice = MyHelper.getChoice("D30021", "Suspension",
part.getContainerReference());
choiceSet = new HashSet<String>();

choiceSet.add(testChoice.getPersistInfo().getObjectIdentifier().toString());
argOptionToChoiceMap.put(testOption.getPersistInfo().getObjectIdentifier().toString(), choiceSet);

// Finally populate the bean with all of this information myRow1Bean.setRowNo(0);

myRow1Bean.setRowNo(0);
myRow1Bean.setVariantSpecName("Bicycle3-VarSpec2");
myRow1Bean.setVariantSpecFolder(folder);
myRow1Bean.setCreateVariants(false);
myRow1Bean.setVariantSpecPart(part);
myRow1Bean.setNavigationCriteria(navCriteria);
myRow1Bean.setOptionSet(optionSet);
myRow1Bean.setUserSelectedOptionChoiceOidMap(optionToChoiceMap);

// Create a list of such beans

ArrayList<VariantSpecLoadOutputBean> variantSpecBeans = new
ArrayList<VariantSpecLoadOutputBean>();
variantSpecBeans.add(myRow1Bean);

//Invoke the API
ArrayList<VariantSpecLoadOutputBean> outputBeans = VariantSpecHelper.service.loadVariantSpecs(variantSpecBeans);

// Check for status on each bean

VariantSpecLoadOutputBean row1Output = outputBeans.get(0);
row1Output.getLoadStatus().getOverAllStatus();
row1Output.getLoadStatus().getVariantSpecNumber();
Boolean.toString(row1Output.getLoadStatus().isVariantSpecCreateSuccess());
Boolean.toString(row1Output.getLoadStatus().isVariantSpecUpdateSuccess()); row1Output.getLoadStatus().getValidationErrorMessage();
row1Output.getLoadStatus().getValidationWarningMessage()