public static void runExample(
AdWordsServices adWordsServices, AdWordsSession session, Long campaignId, Long adGroupId,
Long criterionId) throws Exception {
// Get the ExperimentService.
ExperimentServiceInterface experimentService =
adWordsServices.get(session, ExperimentServiceInterface.class);
// Get the AdGroupService.
AdGroupServiceInterface adGroupService =
adWordsServices.get(session, AdGroupServiceInterface.class);
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService =
adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Create experiment.
Experiment experiment = new Experiment();
experiment.setCampaignId(campaignId);
experiment.setName("Interplanetary Experiment #" + System.currentTimeMillis());
experiment.setQueryPercentage(10);
experiment.setStartDateTime(new DateTime().plusDays(1).toString("yyyyMMdd HHmmss Z"));
// You can optionally provide these field(s).
experiment.setEndDateTime(new DateTime().plusDays(30).toString("yyyyMMdd HHmmss Z"));
// Create operation.
ExperimentOperation experimentOperation = new ExperimentOperation();
experimentOperation.setOperand(experiment);
experimentOperation.setOperator(Operator.ADD);
// Add experiment.
ExperimentReturnValue result =
experimentService.mutate(new ExperimentOperation[] {experimentOperation});
for (Experiment experimentResult : result.getValue()) {
System.out.println("Experiment with name \"" + experimentResult.getName() + "\" and id \""
+ experimentResult.getId() + "\" was added.");
}