The main purpose of this story is to teach children the proper way of treating others. The goatherd was supposed to treat all of his herd well. He should not have shown them less care as those had stuck with him for a long time.
The story also teaches that as we treat others in a positive or negative way, others are observing and may judge us based on what they see. So we should be just and fair in the way we treat others.