// Create an age criterion for age range 18 to 24.
TargetingGroupCriterion ageCriterion = new TargetingGroupCriterion();
ageCriterion.setCampaignId(campaignId);
ageCriterion.setTargetingGroupId(targetingGroupId);
AudienceAge age = new AudienceAge();
age.setAgeRange(AudienceAgeAgeRange.AGE_RANGE_18_24);
ageCriterion.setCriterion(age);
TargetingGroupCriterionOperation addAgeCriterionOp =
new TargetingGroupCriterionOperation();
addAgeCriterionOp.setOperand(ageCriterion);
addAgeCriterionOp.setOperator(Operator.ADD);
// Create a negative age criterion for age 65+.
NegativeTargetingGroupCriterion negativeAgeCriterion =
new NegativeTargetingGroupCriterion();
negativeAgeCriterion.setCampaignId(campaignId);
negativeAgeCriterion.setTargetingGroupId(targetingGroupId);
AudienceAge negativeAge = new AudienceAge();
negativeAge.setAgeRange(AudienceAgeAgeRange.AGE_RANGE_65_UP);
negativeAgeCriterion.setCriterion(negativeAge);
TargetingGroupCriterionOperation addNegativeAgeCriterionOp =
new TargetingGroupCriterionOperation();
addNegativeAgeCriterionOp.setOperand(negativeAgeCriterion);